package c.c.b.b.f;

import android.os.SystemClock;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/* compiled from: VNetLog */
public class q {
    public static boolean a = Log.isLoggable("VNetLog", 2);

    /* compiled from: VNetLog */
    public static class a {
        public static final boolean c = q.a;
        public final List<a> a = new ArrayList();
        public boolean b = false;

        /* compiled from: VNetLog */
        public static class a {
            public final String a;
            public final long b;
            public final long c;

            public a(String str, long j, long j2) {
                this.a = str;
                this.b = j;
                this.c = j2;
            }
        }

        public synchronized void a(String str) {
            long j;
            this.b = true;
            if (this.a.size() == 0) {
                j = 0;
            } else {
                long j2 = ((a) this.a.get(0)).c;
                List list = this.a;
                j = ((a) list.get(list.size() - 1)).c - j2;
            }
            if (j > 0) {
                long j3 = ((a) this.a.get(0)).c;
                q.c("(%-4d ms) %s", Long.valueOf(j), str);
                for (a aVar : this.a) {
                    q.c("(+%-4d) [%2d] %s", Long.valueOf(aVar.c - j3), Long.valueOf(aVar.b), aVar.a);
                    j3 = aVar.c;
                }
            }
        }

        public synchronized void b(String str, long j) {
            if (this.b) {
                throw new IllegalStateException("Marker added to finished log");
            }
            this.a.add(new a(str, j, SystemClock.elapsedRealtime()));
        }

        public void finalize() throws Throwable {
            if (!this.b) {
                a("Request on the loose");
                q.d("Marker log finalized without finish() - uncaught exit point for request", new Object[0]);
            }
        }
    }

    public static void a(String str, Object... objArr) {
        if (a) {
            Log.v("VNetLog", e(str, objArr));
        }
    }

    public static void b(Throwable th, String str, Object... objArr) {
        Log.e("VNetLog", e(str, objArr), th);
    }

    public static void c(String str, Object... objArr) {
        Log.d("VNetLog", e(str, objArr));
    }

    public static void d(String str, Object... objArr) {
        Log.e("VNetLog", e(str, objArr));
    }

    public static String e(String str, Object... objArr) {
        String stringBuilder;
        if (objArr != null) {
            str = String.format(Locale.US, str, objArr);
        }
        StackTraceElement[] stackTrace = new Throwable().fillInStackTrace().getStackTrace();
        for (int i = 2; i < stackTrace.length; i++) {
            if (!stackTrace[i].getClassName().equals("com.bytedance.sdk.adnet.VNetLog")) {
                String className = stackTrace[i].getClassName();
                className = className.substring(className.lastIndexOf(46) + 1);
                StringBuilder i2 = c.b.a.a.a.i(className.substring(className.lastIndexOf(36) + 1), ".");
                i2.append(stackTrace[i].getMethodName());
                stringBuilder = i2.toString();
                break;
            }
        }
        stringBuilder = "<unknown>";
        return String.format(Locale.US, "[%d] %s: %s", new Object[]{Long.valueOf(Thread.currentThread().getId()), stringBuilder, str});
    }
}
